﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thousandClear.Util.Generator
{
    public class SerialNoGenerator
    {
        public string GenerateOrderSerialNo()
        {
            var ran = new Random();
            return string.Format("{0}{1}{2}", "YXG", DateTime.Now.ToString("yyMMddHHmmss"), GetRandStr(6).ToUpper());
        }

        public string GenerateOrderRefundNo()
        {
            var ran = new Random();
            return string.Format("{0}{1}{2}", "YXGF", DateTime.Now.ToString("yyMMddHHmmss"), GetRandStr(6).ToUpper());
        }

        public string GenerateSubscribeSerialNo()
        {
            var ran = new Random();
            return string.Format("{0}{1}{2}", "YXS", DateTime.Now.ToString("yyMMddHHmmss"), GetRandStr(6).ToUpper());
        }

        public string GenerateSubscribeRefundNo()
        {
            var ran = new Random();
            return string.Format("{0}{1}{2}", "YXSF", DateTime.Now.ToString("yyMMddHHmmss"), GetRandStr(6).ToUpper());
        }

        private string GetRandStr(int count)
        {
            Random rnd = new Random();

            StringBuilder sb = new StringBuilder();

            string guid = Guid.NewGuid().ToString().Replace("-", "");

            for (int i = 0; i < count; i++)
            {
                var idx = rnd.Next(0, 32);
                sb.Append(guid.Substring(idx, 1));
            }

            return sb.ToString();
        }
    }
}
